#include "XJMemoryPool.h"
#include <iostream>

class XJMemoryPoolTest{
public:
    int mInt;
    XJMemoryPoolTest(){
        std::cout << "XJMemoryPoolTest() this=" << this << " mInt=" << mInt << std::endl;
    }
    virtual ~XJMemoryPoolTest(){
        std::cout << "~XJMemoryPoolTest() this=" << this << std::endl;
    }
    void *operator new (size_t );
    void operator delete (void * );
};

XJUtilClass::XJMemoryPool<sizeof(XJMemoryPoolTest), 2>  mp;
void *XJMemoryPoolTest::operator  new(size_t s) {
    return mp.malloc();
}
void XJMemoryPoolTest::operator delete(void *p) {
    mp.free(p);
}

int main(){
    XJMemoryPoolTest *p0 = new XJMemoryPoolTest();
    p0->mInt = 100;
    delete p0;
    XJMemoryPoolTest *p1 = new XJMemoryPoolTest();
    XJMemoryPoolTest *p2 = new XJMemoryPoolTest();
    XJMemoryPoolTest *p3 = new XJMemoryPoolTest();
    delete p1;
    delete p2;
    delete p3;
    std::cout << std::endl;    
}